package Server;

import java.util.ArrayList;
import java.util.PriorityQueue;

import org.apache.mina.core.session.IoSession;

public class Notifier extends Thread{
	PriorityQueue<String> queue;
	ArrayList<Subscription> subscriptions;
	
	public Notifier(PriorityQueue<String> q, ArrayList<Subscription> s){
		queue=q;
		subscriptions=s;
		start();
	}
	public void run(){
		while(true){
			if(!queue.isEmpty()){
				sendToAll(queue.poll());
			}
		}
	}
	// broadcast function
    public void sendToAll(String msg){
    	for(int i=0;i<subscriptions.size();i++){
    		subscriptions.get(i).add(msg);
    	}
    }
}
